package com.example.testproj.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.Scroller;

/**
 * @des:
 * @author: 芮勤
 * @date: 19-7-22 10:27
 * @see {@link }
 */
public class MyLinearLayout extends LinearLayout {
    public MyLinearLayout(Context context) {
        super(context);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    Scroller scroller=new Scroller(getContext());

    public void smoothScrollTo(int destX,int destY){
        int scrollX=getScrollX();
        int deltax=destX-scrollX;
        scroller.startScroll(scrollX,0,deltax,0,2000);
        invalidate();
    }


    @Override
    public void computeScroll() {
        super.computeScroll();
        if (scroller.computeScrollOffset()){
            scrollTo(scroller.getCurrX(),scroller.getCurrY());
            //this.setScrollX(scroller.getCurrX());
            postInvalidate();
        }
    }
}
